# 4. 定义敌人类
# --　数据:姓名,血量,基础攻击力,防御力
# --　行为:打印个人信息
# 创建敌人列表(至少４个元素),并画出内存图。
# 查找姓名是"灭霸"的敌人对象
# 查找所有死亡的敌人
# 计算所有敌人的平均攻击力
# 删除防御力小于10的敌人
# 将所有敌人攻击力增加50
class Enemies:
    def __init__(self, name, blood_volume, basic_attack_power, defense):
        self.name = name
        self.blood_volume = blood_volume
        self.basic_attack_power = basic_attack_power
        self.defense = defense

    def print_self_info(self):
        print(self.__dict__)

    @staticmethod
    def print_result(target, name="name", blood_volume="blood_volume", basic_attack_power="basic_attack_power",
                     defense="defense"):
        total_defense = 0
        list_dead_enemy = []
        for i in range(0, len(list_enemy)):
            if target[i][name] == "灭霸":
                print("为您找到了灭霸----%s" % list_enemy[i])
            if target[i][blood_volume] == 0:
                list_dead_enemy.append(list_enemy[i])
                print("死亡的敌人有---%s" % list_dead_enemy)

            total_defense += target[i][defense]
        average_defense = total_defense / len(target)
        print("敌人平均攻击力是%d" % average_defense)

        for i in range(len(list_enemy)-1, -1, -1):
            if target[i][defense] < 10:
                target.remove(target[i])
        print("删除御力小于10的敌人后----%s" % target)

        for i in range(0, len(list_enemy)):
            target[i][basic_attack_power] += 50
        print("将所有敌人攻击力增加50----%s" % target)


list_enemy = [{'name': '隔壁老王', 'blood_volume': 80, 'basic_attack_power': 88, 'defense': 87},
              {'name': '灭霸', 'blood_volume': 50, 'basic_attack_power': 66, 'defense': 99},
              {'name': '隔壁老李', 'blood_volume': 0, 'basic_attack_power': 80, 'defense': 7},
              {'name': '隔壁老林', 'blood_volume': 100, 'basic_attack_power': 50, 'defense': 77}]
enemy01 = Enemies("隔壁老王", 100, 80, 77)
enemy01.print_self_info()

Enemies.print_result(list_enemy)
